#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int find(int x, vector<int>& father, vector<int>& rank)
{
        if(father[x] != x){
                int tmp = father[x];
                father[x] = find(father[x], father, rank);
                rank[x] += rank[tmp];
        }
        return father[x];
}

int merge(int l, int r, int val,vector<int>& father, vector<int>& rank)
{
        int fl = find(l, father, rank);
        int fr = find(r, father, rank);
        if(fl != fr){
                father[fl] = fr;
                rank[fl] = val + rank[r] - rank[l];
                return 1;
        }
        return 0;
}

int check(int l, int r, int val, vector<int>& father, vector<int>& rank)
{
        int fl = find(l, father, rank);
        int fr = find(r, father, rank);
        if(fl == fr){
                return rank[l] - rank[r] == val;
        }
        return true;
}

void run()
{
        int n = 0, m = 0;
        cin >> n >> m;
        vector<int> father(n + 2, 0);
        vector<int> rank(n + 2, 0);
        iota(father.begin(), father.end(), 0);

        for(int i = 0, l = 0, r = 0, val = 0; i < m; i++){
                cin >> l >> r >> val;
                r++;
                if(check(l, r, val, father, rank)){
                        merge(l, r, val, father, rank);
                }else{
                        cout << "false" << endl;
                        return;
                }
        }
        cout << "true" << endl;
        return;
}

int main()
{
        int t = 0;
        cin >> t;
        while(t--){
                run();
        }
        return 0;
}